

#import "FAMHomeBasalMetabolismViewController.h"

@interface FAMHomeBasalMetabolismViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *FAMScrollView;

@property (weak, nonatomic) IBOutlet UILabel *FAMCaloriesLabel;

@end

@implementation FAMHomeBasalMetabolismViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self FAM_showUi];
}
- (void)FAM_showUi{
    self.title = @"Basal metabolism";
    self.FAMScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    NSString *firstChar = [[FAMUserManger shareInstance].userModel.basic_meta substringToIndex:1];
    NSString *lastChar = [[FAMUserManger shareInstance].userModel.basic_meta substringFromIndex:1];
    self.FAMCaloriesLabel.text = [NSString stringWithFormat:@"%@，%@Cal",firstChar,lastChar];
}
- (IBAction)FAM_caloriesTapClick:(UITapGestureRecognizer *)sender {
    FAMHomeCaloriesView *homeCaloriesView = [[FAMHomeCaloriesView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    WeakSelf(self);
    homeCaloriesView.block = ^(NSString * _Nonnull calories) {
        weakSelf.FAMCaloriesLabel.text = [NSString stringWithFormat:@"%@ Cal",calories];
    };
    [self.view addSubview:homeCaloriesView];
}

- (IBAction)FAM_restoreTapClick:(UITapGestureRecognizer *)sender {
    WeakSelf(self)
    [self showHudInKeyWindowWithHint:nil];
    [FAMHttpTool FAM_PutFoodmateUserdataWithParameters:[NSMutableDictionary dictionaryWithDictionary:@{@"data":@{@"basic_meta":@"0"}}] success:^(FAMFoodmateUserdataModel * _Nonnull model, NSString * _Nonnull msg) {
        [FAMHttpTool FAM_GetFoodmateUserdata:^(FAMGetFoodmateUserdataModel * _Nonnull model, NSString * _Nonnull msg) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf hideHudKeyWindow];
                [FAMUserManger shareInstance].userModel = model;
                NSString *firstChar = [[FAMUserManger shareInstance].userModel.basic_meta substringToIndex:1];
                NSString *lastChar = [[FAMUserManger shareInstance].userModel.basic_meta substringFromIndex:1];
                weakSelf.FAMCaloriesLabel.text = [NSString stringWithFormat:@"%@，%@Cal",firstChar,lastChar];
                [[NSNotificationCenter defaultCenter] postNotificationName:@"FAMHomeLoadData" object:nil userInfo:nil];
            });
        } failure:^(NSString * _Nonnull errorInfo) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf showHint:errorInfo];
            });
        }];
    } failure:^(NSString * _Nonnull errorInfo) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf showHint:errorInfo];
        });
    }];
}

@end
